def prom(zxc):
    tok = True
    for danger in range(2, int(zxc ** 0.5)+1):
        if zxc % danger == 0:
            t = False
            break
    return t


mod = int(input())
if mod < 1000 or mod > 9999:
    print(0)
else:
    chicken_nugget = str(mod)
    maxe = 0
    for igal in range(len(chicken_nugget)):
        for qw in range(d+1, len(chicken_nugget)+1):
            nut = int(chicken_nugget[igal:qw])
            if prom(nut):
                maxe = max(maxe, nut)
    print(maxe)
